<script setup lang="ts">
import { UserType } from "../models/user";
import { showToast } from 'vant';

interface UserCardListProps {
  loadings: boolean;
  userList: UserType[];
}

const props = defineProps<UserCardListProps>();

const handleContact = (user: UserType) => {
  showToast(`联系 ${user.userName}`);
  // 这里可以添加联系逻辑，比如跳转到聊天页面
};
</script>

<template>
  <div class="user-card-list">
    <div v-for="user in userList" :key="user.id" class="user-card-wrapper">
      <van-skeleton title avatar :row="3" :loading="loadings">
        <van-card
            :desc="user.profile"
            :title="user.userName"
            :thumb="user.avatarUrl"
            class="user-card"
        >
          <template #tags>
            <div class="tags-container">
              <van-tag 
                v-for="tag in user.tags" 
                :key="tag"
                plain 
                type="primary" 
                class="user-tag"
              >
                {{ tag }}
              </van-tag>
            </div>
          </template>
          <template #footer>
            <van-button 
              size="small" 
              type="primary" 
              class="contact-btn"
              @click="handleContact(user)"
            >
              <van-icon name="chat-o" size="14" />
              联系我
            </van-button>
          </template>
        </van-card>
      </van-skeleton>
    </div>
    
    <van-empty 
      v-if="!userList || userList.length < 1" 
      image="search" 
      description="暂无用户信息"
      class="empty-state"
    >
      <van-button type="primary" @click="$emit('refresh')">
        刷新试试
      </van-button>
    </van-empty>
  </div>
</template>

<style scoped>
.user-card-list {
  padding: 16px;
  background: transparent;
}

.user-card-wrapper {
  margin-bottom: 16px;
  animation: fadeInUp 0.6s ease-out;
}

.user-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
  overflow: hidden;
}

.user-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.user-tag {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.user-tag:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.contact-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-weight: 500;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.contact-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.empty-state {
  margin-top: 60px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  padding: 40px 20px;
  backdrop-filter: blur(10px);
}

/* 深度选择器优化 Vant 组件样式 */
:deep(.van-card__content) {
  padding: 16px;
}

:deep(.van-card__header) {
  padding: 16px 16px 0;
}

:deep(.van-card__footer) {
  padding: 0 16px 16px;
  display: flex;
  justify-content: flex-end;
}

:deep(.van-card__thumb) {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

:deep(.van-card__title) {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 8px;
}

:deep(.van-card__desc) {
  color: #7f8c8d;
  font-size: 14px;
  line-height: 1.5;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .user-card-list {
    padding: 12px;
  }
  
  .user-card-wrapper {
    margin-bottom: 12px;
  }
  
  .tags-container {
    gap: 6px;
  }
  
  .user-tag {
    font-size: 11px;
    padding: 3px 10px;
  }
  
  .contact-btn {
    padding: 6px 12px;
    font-size: 12px;
  }
}
</style>